package cn.tedu.egaddress0805.controller;

import cn.tedu.egaddress0805.mapper.MapperAddress;
import cn.tedu.egaddress0805.pojo.dto.AddParam;
import cn.tedu.egaddress0805.pojo.vo.AddressInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
@ResponseBody
public class AddressController {
    @Autowired
    private MapperAddress mapperAddress;
    @PostMapping("add")
    public String AddressAddParam(@RequestBody AddParam addParam){
        System.out.println(addParam);
        int i = mapperAddress.insertAddressMesage(addParam);
        System.out.println();
        System.out.println("影响了"+i+"条数据");

        return "添加地址成功";
    }
    @GetMapping("list")
    public List<AddressInfoVO> selectAddress(String username){
        System.out.println("传入的username:"+username);
        List<AddressInfoVO> addressInfoVOS = mapperAddress.selectAddress(username);
        for (AddressInfoVO info:addressInfoVOS){
            System.out.println(info);
        }
        return addressInfoVOS;
    }
    @PostMapping("del/{addressId}")
    public String addressDel(@PathVariable Integer addressId){
        int i = mapperAddress.delAddress(addressId);
        System.out.println("删除了"+i+"条数据");
        return "删除地址成功";
    }
}
